<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<title>修改个人信息</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script src="/webjars/miniui/boot.js" type="text/javascript"></script>
<script src="/static/js/common/common.js" type="text/javascript"></script>
<link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="/static/js/aip/AIP_MAIN.js"></script>
<link href="/static/css/default.css" rel="stylesheet" type="text/css"/>
<body>
<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
    <#--<table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <a class="mini-button" onclick="SaveData" style="width:70px" plain="true">保存</a>
                <a class="mini-button" onclick="onCancel" style="width:70px;" plain="true">取消</a>
            </td>
        </tr>
    </table>-->
</div>
<div id="form1" style="margin-top: -15px;">
    <form id="user" method="post">
        <div style="width:100%;height:100%; margin: auto;padding-top: 15px;" align="center">
            <table align="center" width="600px">
                <tr>
                    <td colspan="4" style="width: 100%; text-align: center;">
                        <img id="picture" src="data:image;base64,${avatar!''}"
                             style="width: 100px; height: 100px; border:solid 3px green;border-radius: 5px;"
                             onclick="updateHead()"/>
                    </td>
                </tr>
                <tr>
                    <td colspan="4"></td>
                </tr>
                <tr style="height: 40px">
                    <td style="width:70px;" align="right">账&nbsp;&nbsp;&nbsp;&nbsp;号:</td>
                    <td>${account!''}</td>
                    <td style="width:70px;" align="right">单&nbsp;&nbsp;&nbsp;&nbsp;位:</td>
                    <td>${departname!''}</td>
                </tr>
                <tr style="height: 40px">
                    <td style="width:70px;" align="right"><font color="#dc143c">*</font>姓&nbsp;&nbsp;&nbsp;&nbsp;名:</td>
                    <td><#--${username!''}-->
                        <input id="username" name="username" class="mini-textbox" width="200px" emptyText=""
                               required="true" />
                    </td>
                    <td style="width:70px;" align="right">岗&nbsp;&nbsp;&nbsp;&nbsp;位:</td>
                    <td>${positionname!''}</td>
                </tr>
                <tr style="height: 40px">
                    <td style="width:70px;" align="right"><font color="#dc143c">*</font>手&nbsp;机&nbsp;号:</td>
                    <td >
                        <input id="phone" name="phone" class="mini-textbox" width="200px" emptyText="请输入电话号码"
                               required="false" onblur="checkPhone(phone)"/>
                    </td>
                    <td style="width:70px;" align="right"><font color="#dc143c">*</font>固&nbsp;&nbsp;&nbsp;&nbsp;话:</td>
                    <td >
                        <input id="telphone" name="telphone" class="mini-textbox" width="200px" emptyText="请输入固话"
                               required="false" onblur="checkTelPhone(telphone)"/>
                    </td>
                </tr>
                <tr style="height: 40px">
                    <td style="width:70px;" align="right">邮&nbsp;&nbsp;&nbsp;&nbsp;编:</td>
                    <td >
                        <input id="postcode" name="postcode" class="mini-textbox" width="200px" emptyText="请输入邮编"
                               required="false" />
                    </td>
                    <td style="width:70px;" align="right">邮&nbsp;&nbsp;&nbsp;&nbsp;箱:</td>
                    <td >
                        <input id="email" name="email" class="mini-textbox" width="200px" emptyText="请输入邮箱"
                               required="false"/>
                    </td>
                </tr>
                <tr style="height: 40px">
                    <td style="width:70px;" align="right"><font color="#dc143c">*</font>单位地址:</td>
                    <td colspan="3" style="width: 530px">
                        <input id="positionpro" name="positionpro" class="mini-combobox" required="false" emptyText="省份"
                               textfield="codeName" valueField="codeId" style="width: 23%;"
                               onclick="onDeptChanged('positionpro')" onvaluechanged="onValueChanged('positionpro')"/>
                        <input id="positioncity" name="positioncity" class="mini-combobox" required="false" emptyText="市"
                               textfield="codeName" valueField="codeId" onclick="onDeptChanged('positioncity')"
                               onvaluechanged="onValueChanged('positioncity')" style="width: 23%;"/>
                        <input id="positioncou" name="positioncou" class="mini-combobox" required="false" emptyText="县"
                               textfield="codeName" valueField="codeId" onclick="onDeptChanged('positioncou')"
                               onvaluechanged="onValueChanged('positioncou')" style="width: 23%;"/>
                        <input id="positionvill" name="positionvill" class="mini-combobox" emptyText="街道" style="width: 23%;"
                               textfield="codeName" valueField="codeId" onclick="onDeptChanged('positionvill')" />
                    </td>
                </tr>
            </table>
        </div>
        <div style="padding:2px;margin: 21px;text-align: center" >
            <a class="mini-button" iconCls="fa-save" plain="true" onclick="SaveData()" >保存</a>
            <a class="mini-button" iconCls="fa-close" plain="true" onclick="onCancel()" >取消</a>
        </div>
    </form>
</div>
<script type="text/javascript">
    mini.parse();
    var account = "${account!''}";
    var phone = "${phone!''}";
    var email = "${email!''}";
    var username = "${username!''}";
    var telphone = "${telphone!''}";
    var postcode = "${postcode!''}";

    var positionPro = "${positionPro!''}";
    var positionCity = "${positionCity!''}";
    var positionCou = "${positionCou!''}";
    var positionVill = "${positionVill!''}";
    var positionProName = "${positionProName!''}";
    var positionCityName = "${positionCityName!''}";
    var positionCouName = "${positionCouName!''}";
    var positionVillName = "${positionVillName!''}";

    var positionpro = mini.get("positionpro");
    var positioncity = mini.get("positioncity");
    var positioncou = mini.get("positioncou");
    var positionvill = mini.get("positionvill");


    $("#phone").val(phone);
    $("#email").val(email);
    $("#username").val(username);
    $("#telphone").val(telphone);
    $("#postcode").val(postcode);
    mini.get("#phone").setValue(phone);
    mini.get("#email").setValue(email);
    mini.get("#username").setValue(username);
    mini.get("#telphone").setValue(telphone);
    mini.get("#postcode").setValue(postcode);

    positionpro.setData([{codeId: positionPro, codeName: positionProName}]);
    positioncity.setData([{codeId: positionCity, codeName: positionCityName}]);
    positioncou.setData([{codeId: positionCou, codeName: positionCouName}]);
    positionvill.setData([{codeId: positionVill, codeName: positionVillName}]);

    mini.get("#positionpro").setValue(positionPro);
    mini.get("#positioncity").setValue(positionCity);
    mini.get("#positioncou").setValue(positionCou);
    mini.get("#positionvill").setValue(positionVill);

    function SaveData() {
        var phone = mini.get("#phone").getValue();
        var telphone = mini.get("#telphone").getValue();
        var positionvill = mini.get("#positionvill").getValue();
        var userPositionStr = $("#user").serializeArray();
        if(phone==""){
            mini.alert("电话不能为空");
            return;
        }
        if(telphone==""){
            mini.alert("固话不能为空");
            return;
        }
        if("undefined" == positionvill || positionvill==""){
            mini.alert("地址不能为空");
            return;
        }
        if(checkPhone("phone")==false){
            return;
        }
        if(checkTelPhone("telphone")==false){
            return;
        }
        if(checkEmail("email")==false){
            return;
        }
        //单点登录省份手机号为必填
        var sso = $("#sso").val();
        var phoneFlag = false;  //手机号存在标识
        if (sso){
            if (phone == '') {
                mini.alert("单点登录省份手机号必填");
                return;
            }
            $.ajax({
                url: "/basic/user/phone",
                data:{
                    phoneNum : phone,
                    account : account
                },
                cache: false,
                async: false,
                type: 'post',
                success: function (success) {
                    if (success.code == 1) {
                        phoneFlag = true;
                    } else {
                    }
                }
            });
            if (!phoneFlag) {
                mini.alert("该手机号码已被注册，请重新输入");
                return false;
            }
        }
        var obj = {};
        $.each(userPositionStr,function(i,v){
            obj[v.name] = v.value;
        })
        obj['account'] = account;
        $.ajax({
            url: "/basic/user/user-position-update",
            data: {
                userPositionStr: JSON.stringify(obj)
            },
            type: "post",
            dataType:"JSON",
            success: function (data) {
                if (data.code == 1) {
                    mini.alert("修改成功！")
                } else {
                    mini.alert("修改失败！");
                }
            }
        });
    }

    function onCancel(e) {
        CloseWindow("cancel");
    }

    function updateHead() {
        var url = "/basic/user/user-head/view?account=" + account;
        var win = mini.open({
            url: url,
            allowResize: false,
            showHeader: true,
            title: '编辑头像',
            width: 250,
            height: 100
        });
        win.show();
    }
    //电话号码的验证
    function checkPhone(tel){
        if(mini.get("phone").getValue()==''){
            return true;
        }
        var phone = mini.get("phone").getValue();
        if(!/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(phone)){
            mini.alert('手机号码有误，请重填');
            return false;
        }
    }
    //固定电话验证
    function checkTelPhone(tel){
        if(mini.get("telphone").getValue()==''){
            return true;
        }
        var telphone = mini.get("telphone").getValue();

        if(!/[0]\d{2,3}[-]?\d{7,8}/.test(telphone)){
            mini.alert('固定电话有误，请重填');
            return false;
        }
    }
    //邮箱的验证
    function checkEmail(email) {
        if(mini.get("email").getValue()==''){
            return true;
        }
        var email = mini.get("email").getValue();
        if (!(/^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/.test(email))) {
            mini.alert("邮箱有误，请重填");
            return false;
        }
    }


    function onDeptChanged(e) {
        if ("positionpro" == e) {
            var value = positionpro.getValue();
            positionpro.setValue("");
            var url = "/azbj/getCodeDetail?codeType=2_1&codeId=-1&flag=1";
            positionpro.setUrl(url);
            if(value!=''){
                positionpro.setValue(value);
            } else {
                positionpro.select(0);
            }
        }
        if ("positioncity" == e) {
            var value = positioncity.getValue();
            if(positionpro.getValue()==""){
                positionpro.setUrl(urltemp);
                positionpro.setValue("");
                positioncou.setUrl(urltemp);
                positioncou.setValue("");
                positionvill.setUrl(urltemp);
                positionvill.setValue("");
                return;
            }
            var codeId = positionpro.getValue();
            positioncity.setValue("");
            var url = "/azbj/getCodeDetail?codeType=2_1&codeId=" + codeId;
            positioncity.setUrl(url);
            if(value!=''){
                positioncity.setValue(value);
            } else {
                positioncity.select(0);
            }
        }

        if ("positioncou" == e) {
            var value = positioncou.getValue();
            if(positioncity.getValue()==""){
                positioncou.setUrl(urltemp);
                positioncou.setValue("");
                positionvill.setUrl(urltemp);
                positionvill.setValue("");
                return;
            }
            var codeId = positioncity.getValue();
            positioncou.setValue("");
            var url = "/azbj/getCodeDetail?codeType=2_1&codeId=" + codeId;
            positioncou.setUrl(url);
            if(value!=''){
                positioncou.setValue(value);
            } else {
                positioncou.select(0);
            }
        }

        if ("positionvill" == e) {
            var value = positionvill.getValue();
            if(positioncou.getValue()==""){
                positionvill.setUrl(urltemp);
                positionvill.setValue("");
                return;
            }
            var parent_code = positioncou.getValue();
            positionvill.setValue("");
            var url = "/azbj/getCodeDetail?codeType=2_1&codeId=" + parent_code;
            positionvill.setUrl(url);
            if(value!=''){
                positionvill.setValue(value);
            } else {
                positionvill.select(0);
            }
        }
    }

    function onValueChanged(e) {
        if ("positionpro" == e) {
            positioncity.setValue("");
            positioncou.setValue("");
            positionvill.setValue("");
        }
        if ("positioncity" == e) {
            positioncou.setValue("");
            positionvill.setValue("");
        }
        if ("positioncou" == e) {
            positionvill.setValue("");
        }
    }
</script>
</body>
</html>